<?php
class NewsAction extends Action{
   public function _initialize(){//初始化
		R("Home.Public","top");
		R("Home.Public","bottom");
   }
   public function index(){//新闻动态
	   import("ORG.Com.DiyCache");
	   $mycache=new DiyCache;
	   if(!$mycache->is_cached()){//处理自定义缓存
	     $news = M("news");
		 Vendor("LJW.Page");
		 $count = $news->count();
		 $pagesize = 10;
		 $mypage = new Page($count,$pagesize,3,U("news/index"));
		 $news_list = $news->limit($mypage->start.",".$mypage->pagesize)->order("sequence desc")->findAll();
		 $this->assign("news_list",$news_list);
	     
		 /*分页处理开始*/
		 $f_url=$mypage->url."/p/1";//首页
		 $e_url=$mypage->url."/p/".$mypage->pagenum;//尾页
             
		 $p_url=$mypage->url."/p/".(($mypage->absolutepage-1<=0)?1:($mypage->absolutepage-1));//上一页
		 $n_url=$mypage->url."/p/".(($mypage->absolutepage+1>$mypage->pagenum)?$mypage->pagenum:($mypage->absolutepage+1));//下一页
		 
		 $web_public_path = WEB_PUBLIC_PATH;
		 
		 
		 $div_str = <<<EOT
		 <ul><li><a href="{$f_url}"><img src="{$web_public_path}/images/home/prolist_22.gif" /></a></li><li><a href="{$p_url}"><img src="{$web_public_path}/images/home/prolist_24.gif" /></a></li>
EOT;
        for($i=1;$i<=$mypage->pagenum;$i++){
			    $u=$mypage->url."/p/$i";
			    $div_str.="<li><a href='$u'>$i</a></li>";
		}
		$div_str.=<<<EOT
		<li><a href="{$n_url}"><img src="{$web_public_path}/images/home/prolist_27.gif" /></a></li><li><a href="{$e_url}"><img src="{$web_public_path}/images/home/prolist_29.gif" /></a></li></ul>
EOT;
		 $this->assign("divpage",$div_str);
		 /*分页处理结束*/
	   
	   
	     if(C("diy_cache"))$mycache->create_cache($this->fetch());//创建缓存
	     $this->display();
	   }
   }
   public function news_info(){//新闻详细
       /*安全处理*/
	   checkget();
	   $id=$_GET["id"];
	   if(empty($id)||!is_numeric($id))alert('参数错误');
	   /*安全处理*/
	   
	   import("ORG.Com.DiyCache");
	   $mycache=new DiyCache;
	   if(!$mycache->is_cached()){//处理自定义缓存
	     
	     $news = M("news");
		 $news_info = $news->where("id = $id")->find();
		 $this->assign("news_info",$news_info);
		 
		 
		 //新闻列表
		 Vendor("LJW.Page");
		 $count = $news->count();
		 $pagesize = 10;
		 $mypage = new Page($count,$pagesize,3,U("news/index"));
		 $news_list = $news->limit($mypage->start.",".$mypage->pagesize)->order("sequence desc")->findAll();
		 $this->assign("news_list",$news_list);
	     
		 /*分页处理开始*/
		 $f_url=$mypage->url."/p/1";//首页
		 $e_url=$mypage->url."/p/".$mypage->pagenum;//尾页
             
		 $p_url=$mypage->url."/p/".(($mypage->absolutepage-1<=0)?1:($mypage->absolutepage-1));//上一页
		 $n_url=$mypage->url."/p/".(($mypage->absolutepage+1>$mypage->pagenum)?$mypage->pagenum:($mypage->absolutepage+1));//下一页
		 
		 $web_public_path = WEB_PUBLIC_PATH;
		 
		 
		 $div_str = <<<EOT
		 <ul><li><a href="{$f_url}"><img src="{$web_public_path}/images/home/prolist_22.gif" /></a></li><li><a href="{$p_url}"><img src="{$web_public_path}/images/home/prolist_24.gif" /></a></li>
EOT;
        for($i=1;$i<=$mypage->pagenum;$i++){
			    $u=$mypage->url."/p/$i";
			    $div_str.="<li><a href='$u'>$i</a></li>";
		}
		$div_str.=<<<EOT
		<li><a href="{$n_url}"><img src="{$web_public_path}/images/home/prolist_27.gif" /></a></li><li><a href="{$e_url}"><img src="{$web_public_path}/images/home/prolist_29.gif" /></a></li></ul>
EOT;
		$this->assign("divpage",$div_str);
		/*分页处理结束*/
		 
	     if(C("diy_cache"))$mycache->create_cache($this->fetch());//创建缓存
	     $this->display();
	   }
   }
}
?>